/*
 * ========================================================
 * Copyright(c) 2014 杭州偶尔科技-版权所有
 * ========================================================
 * 本软件由杭州偶尔科技所有, 未经书面许可, 任何单位和个人不得以
 * 任何形式复制代码的部分或全部, 并以任何形式传播。
 * 公司网址
 * 
 * 			http://www.kkkd.com/
 * 
 * ========================================================
 */
package com.simon.mengkou.ui.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.facebook.drawee.drawable.ScalingUtils;
import com.facebook.drawee.generic.GenericDraweeHierarchyBuilder;
import com.facebook.drawee.view.SimpleDraweeView;
import com.simon.mengkou.R;
import com.simon.mengkou.data.bean.base.MessageNotice;
import com.simon.mengkou.data.bean.base.User;
import com.simon.mengkou.data.enums.ELevel;
import com.simon.mengkou.data.enums.ENoticeType;
import com.simon.mengkou.system.global.OuerApplication;
import com.simon.mengkou.system.global.OuerDispatcher;
import com.simon.mengkou.ui.view.AvatarSimpleDraweeView;
import com.simon.mengkou.ui.view.FollowButton;
import com.simon.mengkou.utils.UtilOuer;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * @author : Zhenshui.Xia
 * @since : 2016/3/10.
 * desc    : 消息通知适配器
 */
public class MessageNoticeAdapter extends AbsAdapter<MessageNotice> {

    public MessageNoticeAdapter(Context context) {
        super(context);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup arg2) {
        final Holder holder;
        if (null == convertView) {
            convertView = mInflater.inflate(R.layout.layout_message_notice_item, null);
            holder = new Holder();
            convertView.setTag(holder);
            ButterKnife.bind(holder, convertView);
        } else {
            holder = (Holder) convertView.getTag();
        }

        final MessageNotice data = getItem(position);
        //打开用户详情
        holder.mLlRoot.setOnClickListener(new View.OnClickListener(){

            @Override
            public void onClick(View v) {
                if(data.getType() == ENoticeType.ACTIVITY) {
                    OuerDispatcher.presentWebActivity(mContext, data.getUrl(), data.getTitle());
                }
            }
        });
        //头像
        holder.mSdvAvatar.loadAvatar(data.getAvatarUrl(), ELevel.NORMAL);
        //标题
        holder.mTvTitle.setText(data.getTitle());
        //内容
        holder.mTvContent.setText(data.getContent());
        //时间
        holder.mTvTime.setText(UtilOuer.getFormatDate(mContext, data.getCreatedAt(), "yy-M-d"));

        return convertView;
    }


    /**
     * @author zhenshui.xia
     */
    class Holder {
        //
        @Bind(R.id.follow_id_root)
        LinearLayout mLlRoot;
        //头像
        @Bind(R.id.follow_id_avatar)
        AvatarSimpleDraweeView mSdvAvatar;
        //标题
        @Bind(R.id.follow_id_title)
        TextView mTvTitle;
        //内容
        @Bind(R.id.follow_id_content)
        TextView mTvContent;
        //时间
        @Bind(R.id.follow_id_time)
        TextView mTvTime;
    }
}
